import 'dart:convert';

class User {
  String id;
  String phone;
  String email;
  String username;
  String password;

  User({
    this.id = '',
    this.username = '',
    this.password = '',
    this.email = '',
    this.phone = '',
  });

  factory User.fromJson(dynamic json) {
    Map<String, dynamic> jsonObject;
    if (json is String) {
      jsonObject = jsonDecode(json);
    } else if (json == null) {
      return User();
    } else {
      jsonObject = json;
    }
    return User(
      id: jsonObject['id'] ?? '',
      username: jsonObject['username'] ?? '',
      password: jsonObject['password'] ?? '',
      email: jsonObject['email'] ?? '',
      phone: jsonObject['phone'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'username': username,
      'password': password,
      'email': email,
      'phone': phone,
    };
  }

  @override
  String toString() {
    return jsonEncode(this);
  }
}
